package ltu.m7011e.server.service.impl;

import ltu.m7011e.server.response.login.LoginInfo;
import ltu.m7011e.server.response.login.UserInfoAction;
import ltu.m7011e.server.service.ILoginService;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;


public class LoginService implements ILoginService {
	
	
	private final UserService userService = UserServiceFactory.getUserService();
	
	
	public UserInfoAction LoadLogin() {
		
		    UserInfoAction response = new UserInfoAction();
		    User user = userService.getCurrentUser();
		    String requestUri = "http://ltuquickshare.appspot.com/";
		    
			if (user != null) {
				response.user = new LoginInfo(user.getNickname(),user.getEmail(),userService.createLogoutURL(requestUri),"null",true);
		    } else {
		    	response.user = new LoginInfo("None","None","null",userService.createLoginURL(requestUri),false);
		    }
		// TODO : Call DOA to received LinkEntity from BDD
		// MOCK - Wainting for DOA implmentation			

		  

		return response;
	}
	
	}